from typing import Optional, Any

from pydantic import BaseModel


class Response(BaseModel):
    code: int
    message: str
    data: Optional[Any] = None

    @classmethod
    def success(cls, data: Optional[Any] = None, message: str = "success") -> "Response":
        return cls(code=200, message=message, data=data)

    @classmethod
    def fail(cls, message: str, code: int = 500, data: Optional[Any] = None) -> "Response":
        return cls(code=code, message=message, data=data)

